package wk.demo.activities;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.XXPermissions;
import com.luoye.bzijkplayer.R;

import java.util.List;

import wk.demo.tool.MyToastTool;

public class SplashActivity extends AppCompatActivity {
    private Context context ;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        context= this ;
        requestPermission();


    }


    private void requestPermission() {
        XXPermissions.with(this)
                // 可设置被拒绝后继续申请，直到用户授权或者永久拒绝
                .constantRequest()
                .permission( Manifest.permission.READ_EXTERNAL_STORAGE )
                .permission(  Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean all) {

                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                startActivity(new Intent(context, FileExplorerActivity.class));
                                ((Activity) context).finish();
                            }
                        } ,2000) ;

                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        if (quick) {
                            MyToastTool.toastMsg(context , "拒绝授权将导致APP异常");
                            XXPermissions.startPermissionActivity(context, denied);
                        }
                    }
                });
    }
}
